package com.ease.map {
    import com.kgis.flexutil.ServiceUtil;
    import flash.external.ExternalInterface;
    import mx.messaging.ChannelSet;
    import mx.messaging.channels.AMFChannel;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.remoting.RemoteObject;

    /**
     * amf远程调用对象
     */
    public class RemoteCaller {
        private var cs:ChannelSet = null;
        private var channel:AMFChannel = null;

        public var remoteObject:RemoteObject;

        protected var id:String;

        public function RemoteCaller(destination:String, serverUrl:String = null) {
            if (serverUrl == null) {
                var contextPath:String = ExternalInterface.call("BrowserHistory.getURL");
                serverUrl = ServiceUtil.getDefaultChannelUri(contextPath);
            }
            this.id = id;
            this.remoteObject = new RemoteObject(destination);

            initChannel(serverUrl);

            this.remoteObject.channelSet = cs;
            this.remoteObject.addEventListener(FaultEvent.FAULT, onRemoteException);
        }

        public function onRemoteException(event:FaultEvent):void {

        }

        private function initChannel(serverUrl:String):void {
            cs = new ChannelSet();
            channel = new AMFChannel();
            channel.id = "myAmf";
            channel.uri = serverUrl;
            cs.addChannel(channel);
        }

    }
}